﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace School.WebPages.School
{
    public partial class ExTeacherList : System.Web.UI.Page
    {
        TechnologySchoolEntities db = new TechnologySchoolEntities();
        IEnumerable<Teachers> leaderData = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = "历任领导";
            if (!Page.IsPostBack)
            {
                GetData();
                BindData();
            }
        }

        private void BindData()
        {
            var position = (from p in db.Teachers
                            where p.Position == 2
                            select new
                            {
                                p.PositionName
                            }).Distinct();

            rep_position.DataSource = position;
            rep_position.DataBind();           
        }

        private void GetData()
        {
            leaderData = from l in db.Teachers
                         where l.Position == 2
                         select l;
        }

        protected void rep_position_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater item = (Repeater)e.Item.FindControl("rep_item");
                Label name = (Label)e.Item.FindControl("lblName");
                string positionName = name.Text;

                item.DataSource = leaderData.Where(l => l.PositionName == positionName).OrderBy(l => l.TOrder);
                item.DataBind();
            }
        }
    }
}
